<template>
    <div>
      <el-button size="large" type="primary" @click="openDrawer">新增</el-button>
      <el-drawer v-model="show" size="500" title="新增成绩" :with-header="true">
        <el-form :model="form">
          <el-form-item label="姓名">
            <el-input v-model="form.name" />
          </el-form-item>
          <el-form-item label="年龄">
            <el-input v-model.number="form.age" type="number" />
          </el-form-item>
          <el-form-item label="性别">
            <el-select v-model="form.sex" placeholder="请选择性别">
              <el-option v-for="item in sexList" :label="item.label" :value="item.value" :key="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="语文">
            <el-input v-model.number="form.score.yw" type="number" />
          </el-form-item>
          <el-form-item label="数学">
            <el-input v-model.number="form.score.sx" type="number" />
          </el-form-item>
          <el-form-item label="英语">
            <el-input v-model.number="form.score.yy" type="number" />
          </el-form-item>
          <el-form-item>
            <el-button @click="form = null">重置</el-button>
            <el-button type="primary" @click="submit">提交</el-button>
          </el-form-item>
        </el-form>
      </el-drawer>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        sexList: [{ label: '男', value: '男' }, { label: '女', value: '女' }],
        show: false,
        form: { name: '', age: 0, sex: '', score: { yw: 0, sx: 0, yy: 0 } }
      };
    },
    methods: {
      openDrawer() {
        this.show = true;
      },
      submit() {
        this.$emit('addMember', {...this.form, avatar: require('@/assets/img/avatar' + Math.floor(Math.random() * 10) + '.png')});
        this.form = { name: '', age: 0, sex: '', score: { yw: 0, sx: 0, yy: 0 } };
        this.show = false;
      }
    }
  };
  </script>
  
  <style scoped>
  </style>
  